/**
 * Copyright &copy; 2016-2017 <a href="https://www.lczyfz.com">联创智云</a> All rights reserved.
 */
package com.lczyfz.campusinfo.modules.campusinfo.web;

import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.utils.ApiResultUtils;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.modules.campusinfo.entity.CampusinfoPick;
import com.lczyfz.campusinfo.modules.campusinfo.service.CampusinfoPickService;
import com.lczyfz.campusinfo.modules.sys.security.SystemAuthorizingRealm;
import com.lczyfz.campusinfo.modules.sys.utils.UserUtils;;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 拾物找回Controller
 * @author zms
 * @version 2018-04-16
 */
@Controller
@RequestMapping(value = "api/campusinfo/campusinfoPick")
public class CampusinfoApiPickController extends BaseController {

	@Autowired
	private CampusinfoPickService campusinfoPickService;

	@RequestMapping(value = "pickList")//登记列表
	@ResponseBody
	public Map<String, Object> getcampusinfoPick(CampusinfoPick campusinfoPick, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<CampusinfoPick> page = campusinfoPickService.findPage(new Page<CampusinfoPick>(request, response), campusinfoPick);
		Map<String, Object> map = ApiResultUtils.getBaseMapSuccess();
		map.put("page", page.getList());
		map.put("pageNo", page.getPageNo());
		map.put("count", page.getCount());
		map.put("totalPage",page.getTotalPage());
		return map;
	}
	@RequestMapping(value = "addPick")   //增加登记
	@ResponseBody
	public Map<String, Object> ask(CampusinfoPick campusinfoPick, HttpServletRequest request, HttpServletResponse response, Model model) {
		SystemAuthorizingRealm.Principal principal = UserUtils.getPrincipal();
		campusinfoPick.setUserId(principal.toString());
		Map<String, Object> map = ApiResultUtils.getBaseMapSuccess();
		campusinfoPickService.save(campusinfoPick);
		map.put("message", "拾物登记成功");
		return map;
	}


}